Questions
28 of 30
1What is the purpose of the transform property in CSS?
2What are the different types of CSS transformations?
3What does transform: translate() do?
4What is the difference between translateX() and translateY()?
5How does rotate() work in CSS?
6What is the unit used in rotation?
7What is the difference between scale() and scaleX(), scaleY()?
8What happens when you use negative values in scale()?
9What does the skew() function do?
10Can you combine multiple transform functions together? How? What is the use of the transform-origin property?
11What is the default transform-origin value?
12How does changing transform-origin affect rotation or scaling?
13What is the difference between translate() and using position or margin for movement?
14What is the difference between 2D and 3D transformations?
15What is the difference between 2D and 3D transformations?
16How do you apply a 3D rotation using CSS?
17How do you apply a 3D rotation using CSS?
18What are perspective and perspective-origin in 3D transforms? What is the purpose of transform-style: preserve-3d?
19What is the use of matrix() in CSS transforms?
20What’s the difference between matrix() and matrix3d()?
21How can you center an element using transform and translate()?
22What is the transition property in CSS used for?
23What are the four main components of a transition?
24What does transition-duration specify?
25What are the common timing function values (e.g., ease, linear, ease-in)?
26What is the shorthand syntax for transition?
27Can multiple CSS properties be transitioned simultaneously? How does transition differ from animation in CSS?
28Can you apply a transition to an element’s pseudo-class (like :hover)?
29Can transitions be triggered by JavaScript?
30What happens if transition-duration is set to 0s?
28 / 30

Can you apply a transition to an element’s pseudo-class (like :hover)?

Applying Transitions to Pseudo-classes in CSS

Yes, you can apply transitions to an element’s pseudo-class such as :hover, :focus, or :active. In fact, transitions are most commonly used with these pseudo-classes to create smooth interactive effects when an element changes state.

The transition is declared on the base (default) state of the element, not inside the pseudo-class. This ensures the browser knows how to animate from the initial to the new state when the pseudo-class is triggered.

Example: Applying Transition on :hover

In this example, the button smoothly changes its background color and scales up slightly when hovered, thanks to the transition defined in the default state.

Common Pseudo-classes for Transitions
  1. 1

    :hover — triggered when the user moves the mouse over an element.

  2. 2

    :focus — triggered when an element receives keyboard or programmatic focus.

  3. 3

    :active — triggered when an element is clicked or pressed.

  4. 4

    :checked — triggered when checkboxes or radio buttons are selected.

CSS Example

When the input field gains focus, its border color transitions smoothly from gray to blue.

Key Takeaways
  1. 1

    Declare the transition on the base element, not the pseudo-class.

  2. 2

    Pseudo-classes like :hover, :focus, and :active are ideal for interactive transitions.

  3. 3

    You can transition multiple properties (like color, transform, or opacity) at once.